package xddq

import (
	"fmt"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

// 处理斗法挑战列表
func (xd *XdDriver) CheckDouFaInfoData(allInfo []D.DouFaInfo) {
	fightIdx := -1
	selfCombatVal := xd.UserData.CurrentEquipmentInfo[1].CombatValue
	for _, info := range allInfo {
		log.Infof("斗法列表-第%d位,积分%d,%s 妖力%s", info.Idx+1, info.Points, info.Name, D.GetCombatValueDesc(info.CombatValue))
		if (info.CombatValue/10000)*5 < (selfCombatVal/10000)*4 {
			if fightIdx < 0 {
				fightIdx = int(info.Idx)
			}
		}
	}
	if fightIdx > 0 {
		//需要更换分身
		switchCloneFlag := false
		if xd.UserData.EquipmentCloneFlag && xd.UserData.CurrentEquipmentIdx != 1 {
			switchCloneFlag = true
			xd.SwitchCloneMu.Lock()
			xd.SwitchClone(1)
		}
		log.Infof("开始斗法挑战第%d位,剩余挑战券%d张", fightIdx+1, xd.UserData.ChopDownTree.ChallengeCouponNum)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_RANK_BATTLE_CHALLENGE, fmt.Sprintf("08 %02X", fightIdx)))
		if switchCloneFlag {
			xd.SwitchCloneMu.Unlock()
		}
	} else {
		log.Infof("开始斗法挑战第一位,剩余挑战券%d张", xd.UserData.ChopDownTree.ChallengeCouponNum)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_RANK_BATTLE_CHALLENGE, "0800"))
	}
	if xd.UserData.ChopDownTree.ChallengeCouponNum > 0 {
		xd.ResetTaskByID(proto.S_RANK_BATTLE_GET_BATTLE_LIST)
	}
}
